<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 * @author   howe <howe1995@163.com>
 */

namespace App\Exception;

use Exception;

class BusinessException extends Exception
{
    /**
     * 业务异常构造函数.
     * @param int|string $code 状态码
     * @param string $message 自定义返回信息
     */
    public function __construct(int|string $code, $message = '')
    {
        if (stripos($code, '|') !== false && empty($message)) {
            $arr = explode('|', $code);
            $message = $arr[1];
            $code = $arr[0];
        }
        empty($message) && $message = '未知错误';
        parent::__construct($message, (int) $code);
    }
}
